Attribute VB_Name = "modDB"
Option Explicit


Public md As MyDAO
Public bb As BalanceBroker

Public Sub CreateHosiptalAreaTree(tvw As TreeView)
    Dim sql As String
    Dim rs As Recordset
    Dim rt As Node
    
    sql = "SELECT 'K' + AreaId,AreaName FROM AreaCode WHERE Left(AreaId,4) = '5303'"
    Set rs = md.GetRecordset(sql)
    
    If Not rs.EOF Then
        Set rt = tvw.Nodes.Add(, , rs(0), rs(1))
        rs.MoveNext
    End If
    rt.Expanded = True
    While Not rs.EOF
        tvw.Nodes.Add rt, tvwChild, rs(0), rs(1)
        
        rs.MoveNext
    Wend
        
End Sub

Public Function GetAreasByParent(pid As String) As Recordset
    Set GetAreasByParent = md.GetRecordset("SELECT AreaName FROM AreaCode WHERE ParentId='" & pid & "' ORDER BY AreaId")
End Function
    
Public Sub ComboArea(cbo As ComboBox)
    Dim i As Long
    Dim sql As String
    Dim rs As Recordset
    sql = "SELECT AreaName FROM AreaCode WHERE Left(AreaId,4) = '5303' AND right(AreaId,2) <>'00'"
    Set rs = md.GetRecordset(sql)
    cbo.Clear
    While Not rs.EOF
        cbo.AddItem rs(0)
        rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    cbo.ListIndex = 0
End Sub

Public Sub ComboHospital(cbo As ComboBox)
    Call md.ComboFieldbYSQL(cbo, "SELECT Name FROM Hospital ORDER BY AreaId")
End Sub

Public Function AddHospital(Name As String, Category As String, AreaName As String)
    Dim sql As String
    Dim areaid As String
    areaid = md.GetString("SELECT AreaId FROM AreaCode WHERE AreaName = '" & AreaName & "'")
    
    sql = "INSERT INTO Hospital(Name,Category,AreaId)VALUES('" & Name & "','" & Category & "','" & areaid & "')"
    AddHospital = (md.RunSQL(sql) = 1)
End Function
